package com.mjlf.boot.service;

import com.mjlf.boot.thrift.idl.EventService;
import com.mjlf.boot.thrift.idl.impl.EventServiceImpl;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName ScreenControlService
 * @Author mjlft
 * @Date 2020/3/6 15:39
 * @Version 1.0
 * @Description TODO
 */
public class ScreenControlService {
    public static void start() throws TTransportException {
        TNonblockingServerSocket serverSocket = new TNonblockingServerSocket(8899);
        THsHaServer.Args args1 = new THsHaServer.Args(serverSocket).minWorkerThreads(2)
                .maxWorkerThreads(4)
                .stopTimeoutUnit(TimeUnit.SECONDS);
        EventService.Processor<EventServiceImpl> processor = new EventService.Processor<EventServiceImpl>(new EventServiceImpl());
        args1.protocolFactory(new TCompactProtocol.Factory());
        args1.transportFactory(new TFramedTransport.Factory());
        args1.processorFactory(new TProcessorFactory(processor));

        TServer server = new THsHaServer(args1);
        new Thread(()->{
            server.serve();
        }).start();
        System.out.println(" Thrift Server Started");
    }
}
